using UnityEngine;
using System.Collections;

public class MenuEntryEnding : MonoBehaviour {

	static int sComptor = 0;
	static int sCurrentSelected = 0;

	static bool sWasChanged = false;

	public string GoTo;
	public int Index = 0;

	private int mNumber;

	// Use this for initialization
	void Start()
	{
		if(Index == 0)
		{
			sComptor = 0;
			sCurrentSelected = 0;
		}
		
		mNumber = Index;
		
		if(Index > sComptor)
			sComptor = Index;
	}

	void OnMouseEnter()
	{
		sCurrentSelected = mNumber;
	}

	void OnMouseDown()
	{
		if (GoTo != "")
		{
			if (GoTo == "LeaderBoard")
			{
				HSController.sScore = player.m_Score;
				HSController.sPostScore = true;
			}
			Application.LoadLevel(GoTo);
		}
	}

	// Update is called once per frame
	void Update()
	{
		if (sCurrentSelected == mNumber)
			guiText.material.color = Color.red;
		else
			guiText.material.color = new Color(250 * 0.004f, 120 * 0.004f, 10 * 0.004f); ;

		if (Input.GetAxis("Vertical") < 0 && !sWasChanged)
		{
			sWasChanged = true;
			sCurrentSelected++;

			if (sCurrentSelected > sComptor)
				sCurrentSelected = 0;
		}
		else if (Input.GetAxis("Vertical") > 0 && !sWasChanged)
		{
			sWasChanged = true;
			sCurrentSelected--;

			if (sCurrentSelected < 0)
				sCurrentSelected = sComptor;
		}
		else if (Input.GetAxis("Vertical") == 0)
		{
			sWasChanged = false;
		}

		if (Input.GetAxis("BOMB") > 0 && sCurrentSelected == mNumber)
		{
			OnMouseDown();
		}
	}
}
